#!/bin/bash
set -e

function build() {
    ARCH=$1
    BUILD_DIR="build-${ARCH}"
    TOOLCHAIN_FILE="../cmake/${ARCH}.cmake"

    echo "===== Building for ${ARCH} ====="
    mkdir -p ${BUILD_DIR}
    cd ${BUILD_DIR}
    cmake .. -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FILE} -DCMAKE_BUILD_TYPE=Release
    make -j
#    make install
    cd ..
}

if [ $# -eq 0 ]; then
    build x86_64
    build aarch64
else
    if [ "$1" == "x86_64" ] || [ "$1" == "aarch64" ]; then
        build $1
    else
        echo "Usage: $0 [x86_64|aarch64]"
        exit 1
    fi
fi
